package com.cash.app.manager

import com.cash.app.manager.model.AccountDetailResponse
import com.cash.app.manager.model.AuthenticationProgress

/**
 * Account detail data manager
 */
object AccountInfoManager {

    private var accountInfo: AccountDetailResponse? = null

    fun updateAccountInfo(data: AccountDetailResponse?) {
        accountInfo = data
    }

    // Client ID
    fun getClientId(): String = accountInfo?.client_id ?: ""

    // Subject ID
    fun getSubjectId(): Int = accountInfo?.subject_id ?: 0

    // User mobile number
    fun getUserMobileNumber(): String = accountInfo?.user_mobile_number ?: ""

    // User ID
    fun getUserId(): Int = accountInfo?.uid ?: 0

    // User p_name
    fun getUserName(): String = accountInfo?.user_name ?: ""

    // User AD
    fun getUserAd(): String = accountInfo?.user_ad ?: ""

    // User PAN
    fun getUserPan(): String = accountInfo?.user_pan ?: ""

    // User SDK ID
    fun getUserSdkId(): String = accountInfo?.user_sdk_id ?: ""

    // User gender
    fun getUserGender(): String = accountInfo?.gender ?: ""

    // User head image URL
    fun getHeadImageUrl(): String = accountInfo?.head_img ?: ""

    // Foundation status
    fun isFoundation(): Boolean = accountInfo?.is_foundation == 1

    // Foundation information map
    fun getFoundationInformation(): Map<String, Int> =
        accountInfo?.foundation_information ?: emptyMap()

    // User authentication progress list
    fun getAuthAllProgress(): List<AuthenticationProgress> =
        accountInfo?.user_authentication_progress ?: emptyList()

    // Check if a specific authentication type is completed
    fun isAuthCompleted(authenticationType: Int): Boolean {
        return accountInfo?.user_authentication_progress?.find {
            it.authentication_type == authenticationType
        }?.is_authentication == 1
    }

    // Check if all authentication type are completed
    fun isAuthCompleted(): Boolean {
        var isAuthAll = false
        accountInfo?.user_authentication_progress?.let {
            it.forEach { authItem ->
                isAuthAll = authItem.is_authentication == 1
            }
        }
        return isAuthAll
    }

    // Clear all data
    fun clear() {
        accountInfo = null
    }
} 